#include <iostream>
#include <stdio.h>

#include <iostream>
#include <memory>

// 单链表
struct ListNode {
    int val;  // 节点上存储的元素
    ListNode *next;  // 指向下一个节点的指针
    ListNode(int x) : val(x), next(NULL) {}  // 节点的构造函数
};

class Solution
{
public:
    ListNode* reverseList(ListNode* head){
        ListNode* temp;
        ListNode* cur = head;
        ListNode* pre = NULL;
        while (cur)
        {
            /* code */
            temp = cur->next;
            cur->next = pre;
            pre = cur;
            cur  = temp;
        }
        return pre;
        
    }
};

void printfList(ListNode* header)
{
    ListNode* cur = header;
    while (cur)
    {
        /* code */
        printf("%d ",cur->val);
        if(NULL != cur->next)
            printf("->");
        else
            printf("\n");
        
        cur = cur->next;
    }
    
}


int main(int argv, char**argc)
{

    printf("************  test hello zc!!!   **************\n");
    /* add test code! */
    ListNode * list = new ListNode(0); 
    ListNode* temp;
    ListNode* cur = list;
    list->val = 1;
    for(int i = 0; i< 4; i++){
        temp = new ListNode(2 +i);
        cur->next = temp;
        cur = temp;
    }

    printfList(list);
    Solution solver;
    ListNode * tmp;
    tmp = solver.reverseList(list);
    printfList(tmp);

    return 0;
}
